//
//  JournalViewModel.m
//  DataStatistics
//
//  Created by Kang on 15/12/30.
//  Copyright © 2015年 YTYangK. All rights reserved.
//

#import "JournalViewModel.h"


@interface JournalViewModel()
@end

@implementation JournalViewModel
singleton_for_implementation(JournalViewModel)


static JournalViewModel *journalVM = nil;

+ (JournalViewModel *)getJournalVM {
    if (!journalVM) {
        journalVM = [[super allocWithZone:NULL]init];
    }
    return journalVM;
}
+ (id)allocjournalDataZone:(NSZone *)zone {
    return [self getJournalVM];
}
- (id)copyjournalDataZone:(NSZone *)zone {
    return self;
}
- (id)init {
    if(journalVM) {
        return journalVM;
    }
    self = [super init];
    return self;
}

#pragma mrak - 删除日志
+ (void)requestWithUrlForChangePassword:(id)obj  andParam:(NSDictionary *)param success:(void(^)(JournalModel * model))success failure:(void(^)(NSString * error))failure{

    MDC_INTER_DIC(@"alarm/alarmRemove.asp", @"NetMethodPOST", @"ture")
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
    
        if ([model[@"result"] intValue] != 1) {
            failure(@"删除失败");
            return;
        }
        success(model[@"result"]);
        
    } failure:^(id obj, NSString *err) {
        // [MBProgressHUD showError:err]; //返回是因为需要列表拉下来
        failure(err);
    }];
    
}


#pragma mrak - 日志列表
+ (void)requestWithUrlForJournal:(id)obj andParam:(NSDictionary *)param
                          success:(void(^)(JournalModel *model))success failure:(void(^)(NSString *error))failure {
    
    MDC_INTER_DIC(@"alarm/alarmList.asp", @"NetMethodGET", @"false")
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
        JournalModel * journ = [[JournalModel alloc] initWithDictionary:model error:nil];
        
        
        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
        [defaults setObject:@(journ.alarm) forKey:@"name"];

        
        if (![journ.JouList isEqual:[NSNull null]]) {
            success(journ);
            return;
        }
        failure(@"---");

    } failure:^(id obj, NSString *err) {
        failure(err); //返回是因为需要列表拉下来
    }];
    
}

#pragma mrak - 跳转日志详情
+ (void)journalDetailWithListModel:(JournalModel *)model forViewController:(id)vc {
    [vc performSegueWithIdentifier:@"gotoLogInfoC" sender:vc];
}


#pragma mrak - 清除未读信息
+ (void)requestWithUrlForRemoveUnreadNum:(id)obj andParam:(NSDictionary *)param
                                 failure :(void(^)(NSString *mag))failure   {
    
    MDC_INTER_DIC(@"alarm/updateReadList.asp", @"NetMethodPOST", @"ture")
    [super initRequestWithUrlObj:obj parametersDic:param Interface:inter success:^(id obj, id model) {
        failure(@"---");
    } failure:^(id obj, NSString *err) {
        [MBProgressHUD showError:err]; //返回是因为需要列表拉下来
    }];
    

    
}

@end
